<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@ page import="model.*"%>
<%
	DocumentModel obj;
	Object temp = request.getAttribute("document");
	if (temp != null) {
		try {
			obj = (DocumentModel) temp;
		} catch (Exception ex) {
			obj = new DocumentModel();
		}
	} else {
		obj = new DocumentModel();
	}
%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Create New Document</title>
<script language="javascript" type="text/javascript"
	src="js/datepicker.js"></script>
<link rel="stylesheet" href="css/datepicker.css" />
<link rel="stylesheet" href="css/common.css" />
<script language="javascript" type="text/javascript" src="js/common.js"></script>
<script language="javascript" type="text/javascript"
	src="js/jquery-1.6.1.min.js"></script>

<script language="javascript" type="text/javascript">
	var requiredInputs = [['name','name_required'],['code','code_required'],['description','description_required'],['object_type','object_type_required'],['object_id','object_id_required'],['status','status_required'],['notification','notification_required']];
	var intInputs = [['object_id','object_id_invalid'],['status','status_invalid'],['notification','notification_invalid']];
	var doubleInputs = [];
	var dateInputs = [];
	var timeInputs = [];

	function checkInputs() {
		var valid = true;

		if (checkRequiredInputs(requiredInputs) == false) {
			valid = false;
		}
		if (checkIntInputs(intInputs) == false) {
			valid = false;
		}
		if (checkDoubleInputs(doubleInputs) == false) {
			valid = false;
		}
		if (checkDateInputs(dateInputs) == false) {
			valid = false;
		}
		if (checkTimeInputs(timeInputs) == false) {
			valid = false;
		}

		// SPECIFIC VALIDATE CODE HERE		

		return valid;
	}
</script>
</head>
<body>
	<jsp:include page="menu.jsp"></jsp:include>
	<form action="document?mode=insert" method="post"
		onSubmit="return checkInputs()"
		onreset="return confirm('Do you really want to reset the form?')">
		<table class="tblInput" border="1">
			<tr class="inputHeader">
				<td colspan="3" class="inputHeader">Create New Document</td>
			</tr>
			<tr class="trField">
				<td class="tdFieldName">Name</td>
				<td class="tdFieldInput"><input class="inputText" type="text"
					id="name" name="name" maxlength="255" value="<%=obj.getName()%>" />
				</td>
				<td class="tdErrMsg"><span id="name_required" class="errMsg"
					style="display: none;">Name is required</span> <span
					id="name_invalid" class="errMsg" style="display: none;">Name
						is invalid</span> <span id="name_error" class="errMsg"><%=obj.errMsgs.Name%></span>
				</td>
			</tr>
			<tr class="trField">
				<td class="tdFieldName">Code</td>
				<td class="tdFieldInput"><input class="inputText" type="text"
					id="code" name="code" maxlength="20" value="<%=obj.getCode()%>" />
				</td>
				<td class="tdErrMsg"><span id="code_required" class="errMsg"
					style="display: none;">Code is required</span> <span
					id="code_invalid" class="errMsg" style="display: none;">Code
						is invalid</span> <span id="code_error" class="errMsg"><%=obj.errMsgs.Code%></span>
				</td>
			</tr>
			<tr class="trField">
				<td class="tdFieldName">Description</td>
				<td class="tdFieldInput"><textarea id="description"
						name="description" rows="5" class="inputTextarea"><%=obj.getDescription()%></textarea>
				</td>
				<td class="tdErrMsg"><span id="description_required"
					class="errMsg" style="display: none;">Description is
						required</span> <span id="description_invalid" class="errMsg"
					style="display: none;">Description is invalid</span> <span
					id="description_error" class="errMsg"><%=obj.errMsgs.Description%></span>
				</td>
			</tr>
			<tr class="trField">
				<td class="tdFieldName">Is Template</td>
				<td class="tdFieldInput">
					<table class="tblBool">
						<tr class="trBoolSet">
							<td colspan="2" class="tdBoolSet"><input type="checkbox"
								id="ckb_is_template" name="ckb_is_template"
								onchange="toggleControls(['is_template_true', 'is_template_false'])" />Not
								set</td>
						</tr>
						<tr class="trBool">
							<td class="tdBool"><input type="radio" id="is_template_true"
								name="is_template" value="1" checked="checked" />Yes</td>
							<td class="tdBool"><input type="radio"
								id="is_template_false" name="is_template" value="0" />No</td>
						</tr>
					</table></td>
				<td class="tdErrMsg"></td>
			</tr>
			<tr class="trField">
				<td class="tdFieldName">Object Type</td>
				<td class="tdFieldInput"><input class="inputText" type="text"
					id="object_type" name="object_type" maxlength="50"
					value="<%=obj.getObjectType()%>" />
				</td>
				<td class="tdErrMsg"><span id="object_type_required"
					class="errMsg" style="display: none;">Object Type is
						required</span> <span id="object_type_invalid" class="errMsg"
					style="display: none;">Object Type is invalid</span> <span
					id="object_type_error" class="errMsg"><%=obj.errMsgs.ObjectType%></span>
				</td>
			</tr>
			<tr class="trField">
				<td class="tdFieldName">Object Id</td>
				<td class="tdFieldInput"><input class="inputInt" type="text"
					id="object_id" name="object_id" maxlength="10"
					value="<%=obj.getObjectId()%>" />
				</td>
				<td class="tdErrMsg"><span id="object_id_required"
					class="errMsg" style="display: none;">Object Id is required</span>
					<span id="object_id_invalid" class="errMsg" style="display: none;">Object
						Id is invalid</span> <span id="object_id_error" class="errMsg"><%=obj.errMsgs.ObjectId%></span>
				</td>
			</tr>
			<tr class="trField">
				<td class="tdFieldName">Need Approval</td>
				<td class="tdFieldInput">
					<table class="tblBool">
						<tr class="trBoolSet">
							<td colspan="2" class="tdBoolSet"><input type="checkbox"
								id="ckb_need_approval" name="ckb_need_approval"
								onchange="toggleControls(['need_approval_true', 'need_approval_false'])" />Not
								set</td>
						</tr>
						<tr class="trBool">
							<td class="tdBool"><input type="radio"
								id="need_approval_true" name="need_approval" value="1"
								checked="checked" />Yes</td>
							<td class="tdBool"><input type="radio"
								id="need_approval_false" name="need_approval" value="0" />No</td>
						</tr>
					</table></td>
				<td class="tdErrMsg"></td>
			</tr>
			<tr class="trField">
				<td class="tdFieldName">Status</td>
				<td class="tdFieldInput"><input class="inputInt" type="text"
					id="status" name="status" maxlength="10"
					value="<%=obj.getStatus()%>" />
				</td>
				<td class="tdErrMsg"><span id="status_required" class="errMsg"
					style="display: none;">Status is required</span> <span
					id="status_invalid" class="errMsg" style="display: none;">Status
						is invalid</span> <span id="status_error" class="errMsg"><%=obj.errMsgs.Status%></span>
				</td>
			</tr>
			<tr class="trField">
				<td class="tdFieldName">Is Draft</td>
				<td class="tdFieldInput">
					<table class="tblBool">
						<tr class="trBoolSet">
							<td colspan="2" class="tdBoolSet"><input type="checkbox"
								id="ckb_is_draft" name="ckb_is_draft"
								onchange="toggleControls(['is_draft_true', 'is_draft_false'])" />Not
								set</td>
						</tr>
						<tr class="trBool">
							<td class="tdBool"><input type="radio" id="is_draft_true"
								name="is_draft" value="1" checked="checked" />Yes</td>
							<td class="tdBool"><input type="radio" id="is_draft_false"
								name="is_draft" value="0" />No</td>
						</tr>
					</table></td>
				<td class="tdErrMsg"></td>
			</tr>
			<tr class="trField">
				<td class="tdFieldName">Notification</td>
				<td class="tdFieldInput"><input class="inputInt" type="text"
					id="notification" name="notification" maxlength="10"
					value="<%=obj.getNotification()%>" />
				</td>
				<td class="tdErrMsg"><span id="notification_required"
					class="errMsg" style="display: none;">Notification is
						required</span> <span id="notification_invalid" class="errMsg"
					style="display: none;">Notification is invalid</span> <span
					id="notification_error" class="errMsg"><%=obj.errMsgs.Notification%></span>
				</td>
			</tr>

			<tr class="trInputBottom">
				<td class="trInputBottom" colspan="3">
					<table class="tblSubmit" align="center">
						<tr class="trSubmit">
							<td class="tdSubmit"><input type="submit" value="Submit" />
							</td>
							<td class="tdReset"><input type="reset" value="Reset" /></td>
						</tr>
					</table></td>
			</tr>
		</table>
	</form>
</body>
</html>